﻿// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using Newtonsoft.Json.Linq;
using JsonCSharpClassGenerator;
using TomatoSynchronizer.Store;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace TomatoSynchronizer.Entities 
{

    public class SlideImage 
    {
    	public override bool Equals(object obj)
		{
			if(obj is SlideImage)
			{
				SlideImage image = (SlideImage)obj;
				
				if(image.sort_order  == _sort_order && image.status == _status)
				{
					MappingStore mappingStore = new MappingStore(store.site,image.store.site,"languages_id");
					
					foreach(Mapping mapping in mappingStore.Mappings)
					{
						try
						{																					
							if(_image_urls["image_url[" + mapping.SrcValue + "]"] != image.image_urls["image_url[" + mapping.DestValue + "]"])
							{
								return false;
							}	
							
							if(_descriptions["description[" + mapping.SrcValue + "]"] != image.descriptions["description[" + mapping.DestValue + "]"])
							{
								return false;
							}
							
							if(_slide_images["slide_image" + mapping.SrcValue] != image.slide_images["slide_image" + mapping.DestValue])
							{
								return false;
							}														
						}
						catch(KeyNotFoundException ex)
						{
							throw ex;
						}
					}
					return true;
				}
			}
			
			return false;
		}
    	
        public SlideImage()
        {
        }

        public SlideImage(string json)
         : this(JObject.Parse(json))
        {
        }

        private JObject __jobject;
        public SlideImage(JObject obj)
        {
            this.__jobject = obj;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        private SlideImageStore store;

        public SlideImageStore Store
        {
           get{
            return store;}
           set{
            store = value;}
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _image_id;
        public string image_id
        {
            get
            {
                if(_image_id == null)
                    _image_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "image_id"));
                return _image_id;
            }
            set
            {
                _image_id = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _language_id;
        public string language_id
        {
            get
            {
                if(_language_id == null)
                    _language_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "language_id"));
                return _language_id;
            }
            set
            {
                _language_id = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _description;
        public string description
        {
            get
            {
                if(_description == null)
                    _description = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "description"));
                return _description;
            }
            set
            {
                _description = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _image;
        public string image
        {
            get
            {
                if(_image == null)
                    _image = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "image"));
                return _image;
            }
            set
            {
                _image = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _image_url;
        public string image_url
        {
            get
            {
                if(_image_url == null)
                    _image_url = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "image_url"));
                return _image_url;
            }
            set
            {
                _image_url = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _sort_order;
        public string sort_order
        {
            get
            {
                if(_sort_order == null)
                    _sort_order = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "sort_order"));
                return _sort_order;
            }
            set
            {
                _sort_order = value;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string _status;
        public string status
        {
            get
            {
                if(_status == null)
                    _status = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "status"));
                return _status;
            }
            set
            {
                _status = value;
            }
        }        
        
        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _descriptions;
		public Dictionary<string, string> descriptions
		{
			get
			{
				if(_descriptions == null)
				{
					_descriptions = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_descriptions["description[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"description[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _descriptions;
			}
			set
			{
				_descriptions = value;
			}
		}                       
        
        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _image_urls;
		public Dictionary<string, string> image_urls
		{
			get
			{
				if(_image_urls == null)
				{
					_image_urls = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_image_urls["image_url[" + language.languages_id + "]"] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"image_url[" + language.languages_id + "]"));
							}
						}
					}
				}
				
				return _image_urls;
			}
			set
			{
				_image_urls = value;
			}
		}                      
        
        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private Dictionary<string, string> _slide_images;
		public Dictionary<string, string> slide_images
		{
			get
			{
				if(_slide_images == null)
				{
					_slide_images = new Dictionary<string, string>();
					
					if(__jobject != null)
					{
						if(store != null)
						{
							var languages = store.site.GetLanguageStore().LoadItems();
							
							foreach(Language language in languages)
							{
								_slide_images["slide_image" + language.languages_id] = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject,"slide_image" + language.languages_id));
							}
						}
					}
				}
				
				return _slide_images;
			}
			set
			{
				_slide_images = value;
			}
		}               

    }
}
